// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class SocketTest extends cc.Component {


    // LIFE-CYCLE CALLBACKS:

    socket: Socket = null

    onLoad () {}

    start () {
        this.socket = io.connect('http://127.0.0.1:7001');
        console.log(this.socket);
        this.socket.on('connect', ()=>{
            console.log('连接成功');
            
        })
        // 接收服务器的to-client消息
        this.socket.on('to-client', (d)=>{
            console.log(d);
        })
        
        // 判断是否断开连接
        this.socket.on('disconnecting',reason=>{ 
            console.log('断开连接');
            
        })
    }

    // update (dt) {}
}
